package com.flbill.controller;
import com.flbill.common.result.Result;
import com.flbill.pojo.entity.User;
import com.flbill.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user")
public class UserController {
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    //查询个人信息
    @GetMapping("/profile")
    public Result<User> getUserInfo() {
        User user = userService.getUser();
        return Result.success(user);
    }

    //签到
    @PostMapping("/sign-in")
    public Result signIn() {
        userService.signIn();
        return Result.success("签到成功");
    }

    //统计月签到数
    @GetMapping("/sign-in/count")
    public Result<Integer> countSignIn() {
        return Result.success(userService.countSignIn());
    }

    //查询今日是否已经签到
    @GetMapping("/sign-in/check")
    public Result<String> checkSignIn() {
        Boolean checkSignIn = userService.checkSignIn();
        if(checkSignIn){
            return Result.success("签到成功");
        }
        return  Result.error("今日已经签到");
    }

}
